<?php
declare (strict_types=1);

namespace app\admin\controller\base;

use app\admin\model\base\SysSignPoint as SysSignPointModel;
use app\BaseController;
use think\facade\Request;
use think\response\Json;

/**
 * 系统埋点管理
 */
class SysSignPoint extends BaseController
{

    /**
     * 系统埋点枚举
     * @return Json
     */
    public function pointAll(): Json
    {
        $pointArr = SysSignPointModel::$pointArr;
        return jsonReturn(1, $pointArr);
    }

    /**
     * 系统埋点列表
     * @return Json
     */
    public function pointList(): Json
    {
        $params['point'] = Request::param('point/s');
        $params['page'] = Request::param('page/d', 1);
        $params['limit'] = Request::param('limit/d', 10);
        $params['start_time'] = Request::param('start_time/d', 0);
        $params['end_time'] = Request::param('end_time/d', 0);
        //条件筛选
        $where = [];
        if ($params['point']) {
            $where[] = ['point', '=', $params['point']];
        }
        //创建时间筛选
        if ($params['start_time'] && $params['end_time']) {
            $start_time = (int)$params['start_time'];
            $end_time = (int)$params['end_time'];
            $where[] = ['create_time', 'between', [$start_time, $end_time]];
        }
        $data = SysSignPointModel::getList($where, $params['page'], $params['limit'], 'id desc');
        return jsonReturn(1, $data);
    }

}
